<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-02-07 08:50:24
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-11-09 12:59:29
 * @Description: 
 * 
-->
<template>
  <el-dialog  draggable overflow :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
    <el-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
          <el-form-item label="标识" prop="key">
            <el-input v-model="form.key" clearable></el-input>
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" clearable></el-input>
          </el-form-item>
          <el-form-item label="规则" prop="setting">
            <el-input v-model="form.setting" clearable></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" clearable></el-input>
          </el-form-item>
          <el-form-item label="注意事项">
            一般字母开头且不超过4位 ,字母开头<br>
            {y}：年份(2位)&nbsp;&nbsp;&nbsp;{m}：月份(2位)&nbsp;&nbsp;&nbsp;{d}：天数(2位)<br>
            {H}：小时(2位)&nbsp;&nbsp;&nbsp;{i}：分钟(2位)&nbsp;&nbsp;&nbsp;{s}：秒数(2位)<br>
            {Y}：年份(4位)&nbsp;&nbsp;&nbsp;{p}：结合程序代码自动变化首字母&nbsp;&nbsp;<br>
            {xxxx}：自增序列号(建议控制在1-6位)<br>
          </el-form-item>
        </el-form>
      </el-tab-pane>

    </el-tabs>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  emits: ["success", "closed"],
  data() {
    return {
      mode: "add",
      titleMap: {
        add: "新增APP",
        edit: "编辑APP",
      },
      form: {
        id: "",
        key: "",
        name: "",
        remark: "",
        setting: [],
      },
      rules: {
        key: [{ required: true, message: "请输入标识" }],
        name: [{ required: true, message: "请输入名称" }],
        setting: [{ required: true, message: "请设置规则" }],
      },
      visible: false,
      isSaveing: false,
    };
  },
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          var res = await this.$API.system.autocode.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
        }
      });
    },
    //表单注入数据
    setData(data) {
      this.form.id = data.id;
      this.form.key = data.key;
      this.form.name = data.name;
      this.form.remark = data.remark;
      this.form.setting = data.setting;
    },
  },
};
</script>

<style></style>
